#ifndef MYOPENGLWIDGET_H
#define MYOPENGLWIDGET_H

#include <QWidget>
#include <QOpenGLWidget>
#include <QOpenGLFunctions_3_3_Core>
#include <QOpenGLShaderProgram>
#include <QOpenGLTexture>
#include <QOpenGLBuffer>
#include <QOpenGLVertexArrayObject>


class MyOpenGLWidget : public QOpenGLWidget, public QOpenGLFunctions_3_3_Core
{
    Q_OBJECT

public:
    explicit MyOpenGLWidget();
    ~MyOpenGLWidget();

protected:
    void initializeGL()override;
    void resizeGL(int width, int height)override;
    void paintGL()override;

    //重写键盘事件
    void keyPressEvent(QKeyEvent *event)override;
    //重写鼠标事件
    void mouseMoveEvent(QMouseEvent *event)override;


private:
    QOpenGLShaderProgram *_shaderProgram;
    QOpenGLShaderProgram *_shaderProgram1;
    QOpenGLTexture *_texture;
    QOpenGLTexture *_texture1;
    QOpenGLVertexArrayObject *_vao;
    QOpenGLVertexArrayObject *_vao1;
    QOpenGLBuffer *_vbo;
    QOpenGLBuffer *_ebo;

    //帧处理时间
    int _lastMescCount = 0;
    float _deltaTime = 0;

    //摄像机相关
    QVector3D _cameraPos = {0.0f, 0.0f, 3.0f};
    QVector3D _cameraFront = {0.0f, 0.0f, -1.0f};
    QVector3D _cameraUp = {0.0f, 1.0f, 0.0f};
    float _moveSpeed = 5.0f;
    float _yaw = -90.0f;
    float _pitch = 0.0f;
    float _sensitivity = 0.1f;

    //屏幕中心点
    QPoint _lastMousePos = rect().center();

};

#endif // MYOPENGLWIDGET_H
